/**
 * ReportGear(2011)
 */
package com.reportgear.designer.action.file;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;

import javax.swing.JFrame;

import com.reportgear.core.util.ImageUtils;
import com.reportgear.designer.action.ReportAction;
import com.reportgear.report.context.ReportContext;
import com.reportgear.report.model.ReportModel;
import com.reportgear.report.print.PreviewPane;
import com.reportgear.report.view.JWorksheet;
import com.reportgear.swing.util.GuiUtils;

/**
 * 打印预览 Action
 * 
 * @version 1.0 2011-4-13
 * @author <a herf="lexloo@gmail.com">lexloo</a>
 * @since Report 1.0
 */
public class PagePreviewAction extends ReportAction {

	private PreviewPane preview = new PreviewPane();

	public PagePreviewAction() {
		setName("预览");
		setMnemonic('V');
		setSmallIcon(ImageUtils.readIcon("/resources/images/file/preview.png"));
	}

	public void actionPerformed(ActionEvent e) {
		JFrame frame = new JFrame();
		frame.setMinimumSize(new Dimension(800, 600));
		frame.setPreferredSize(new Dimension(800, 600));
		frame.setLayout(new BorderLayout());

		JWorksheet worksheet = ReportContext.INSTANCE.getCurrentWorkSheet();
		ReportModel report = worksheet.getReportModel();
		preview.print(report);

		frame.add(preview, BorderLayout.CENTER);
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);

		GuiUtils.centerWindow(frame);
		frame.setVisible(true);
	}
}